package leetcode.D100.T14;

/**
 * @File Info: leetcode -- <Solution>
 * @Author: 18362
 * @Create: 2022-02-25 16:37:01 星期五
 */
class Solution {
    public String longestCommonPrefix(String[] strs) {
        StringBuilder sb = new StringBuilder();
        for(int i=0; i<strs[0].length(); ++i) {
            boolean flag = true;
            char c = strs[0].charAt(i);
            for(int j=1; j<strs.length; ++j) {
                if (i >= strs[j].length() || strs[j].charAt(i) != c) {
                    flag = false;
                    break;
                }
            }
            if (!flag)
                break;
            sb.append(c);
        }
        return sb.toString();
    }
}